package leetcode;

import Tree.CreateByPreAndIn;
import Tree.TreeNode;

public class MinimumDepthOfTree {

	static int min = Integer.MAX_VALUE;
	public static void main(String[] args) {
		int[] pre = {1,2};
		int[] in = {2,1};
		TreeNode root = CreateByPreAndIn.reConstructBinaryTree(pre, in);
		getMinDepth(root);
	}
	public static int getMinDepth(TreeNode root){
		if (root == null) {
			return 0;
		}
		min = Integer.MAX_VALUE;  //以后使用全局变量时务必小心，因为Oj可能是调用这个该函数多次
                                  //而不是运行该程序多次，这导致全局变量的值不会变的
		getPath(root, 1);
		return min;
	}
	
	public static void getPath(TreeNode root, int curDepth){
		if(root.left == null && root.right == null){
			if(curDepth < min){
				min = curDepth;
				System.out.println(min);
			}
		}
		if(root.left != null){
			getPath(root.left, curDepth + 1);
		}
		if(root.right != null){
			getPath(root.right, curDepth + 1);
		}
	}
}
